package android.demo.activity.passvalue;

import android.content.Intent;
import android.demo.BaseActivity;
import android.demo.R;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class FirstActivity extends BaseActivity {

	private EditText etUsername, etPassword;
	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.first);

		Button btn = (Button) findViewById(R.id.btnNext);
		btn.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				etUsername = (EditText) findViewById(R.id.etUsername);
				etPassword = (EditText) findViewById(R.id.etPassword);
				
				String username = etUsername.getText().toString();
				String password = etPassword.getText().toString();
				
				Bundle data = new Bundle();
				data.putString("username", username);
				data.putString("password", password);
				
				Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
				intent.putExtras(data);
				startActivityForResult(intent, 0);
			}
		});
	}
	
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		
		Log.i(TAG, this + "@" + this.getTaskId()  + " ................onActivityResult");
		Bundle b = data.getExtras();
		String username = b.getString("username");
		String password = b.getString("password");
		
		etUsername.setText(username + "NEW");
		etPassword.setText(password + "NEW");
	}
}
